package com.yyfax.pay.third.model.to.baofu;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.yyfax.framework.model.Content;


/**
 * 批量同步返回对象
 * @author maojian
 * @date Apr 27, 2017
 * @since TODO(说明当前修改版本号)
 */
@SuppressWarnings("serial")
public class QueryPayinBatchOrderBaoFuContent extends Content{
	
	public static final String SUCCESS = "000000";

	@JSONField(name="resp_code")  
	private String respCode;
	@JSONField(name="resp_msg")  
	private String respMsg;
	@JSONField(name="member_id")  
	private String memberId;
	@JSONField(name="terminal_id")  
	private String terminalId;
	@JSONField(name="batch_id")  
	private String batchId;
	
	private List<QueryPayinBatchContentItem> items;
	/**
	 * 请求内容
	 */
	@JsonIgnore
	private String reqContent;

	public String getRespCode() {
		return respCode;
	}
	public void setRespCode(String respCode) {
		this.respCode = respCode;
	}
	public String getRespMsg() {
		return respMsg;
	}
	public void setRespMsg(String respMsg) {
		this.respMsg = respMsg;
	}
	public String getMemberId() {
		return memberId;
	}
	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}
	public String getTerminalId() {
		return terminalId;
	}
	public void setTerminalId(String terminalId) {
		this.terminalId = terminalId;
	}
	public String getBatchId() {
		return batchId;
	}
	public void setBatchId(String batchId) {
		this.batchId = batchId;
	}

	public String getReqContent() {
		return reqContent;
	}
	public void setReqContent(String reqContent) {
		this.reqContent = reqContent;
	}
	
    public List<QueryPayinBatchContentItem> getItems() {
		return items;
	}
	public void setItems(List<QueryPayinBatchContentItem> items) {
		this.items = items;
	}


	public static class QueryPayinBatchContentItem{
    	
    	public static final String ENCRYPTSEPERATOR = "#";
    	/**
    	 * @Fields trans_id : 商户订单号 唯一订单号，8-50 位字母和数字，
    	 */
    	@JSONField(name="trans_id")  
    	private String transId;
    	/**
    	 * @Fields order_stat : 交易状态，
    	 */
    	@JSONField(name="order_stat")  
    	private String orderStat;
    	/**
    	 * @Fields resp_code : 应答码，
    	 */
    	@JSONField(name="resp_code")  
    	private String respCode;
    	/**
    	 * @Fields resp_msg : 应答信息，
    	 */
    	@JSONField(name="resp_msg")  
    	private String respMsg;
    	/**
    	 * @Fields trans_no : 宝付交易号，
    	 */
    	@JSONField(name="trans_no")  
    	private String transNo;
    	/**
    	 * @Fields succ_amt : 成功金额，
    	 */
    	@JSONField(name="succ_amt")  
    	private String succAmt;
    	/**
    	 * @Fields req_reserved : 请求方保留域，
    	 */
    	@JSONField(name="req_reserved")  
    	private String reqReserved;

		public String getTransId() {
			return transId;
		}

		public void setTransId(String transId) {
			this.transId = transId;
		}

		public String getOrderStat() {
			return orderStat;
		}

		public void setOrderStat(String orderStat) {
			this.orderStat = orderStat;
		}

		public String getRespCode() {
			return respCode;
		}

		public void setRespCode(String respCode) {
			this.respCode = respCode;
		}

		public String getRespMsg() {
			return respMsg;
		}

		public void setRespMsg(String respMsg) {
			this.respMsg = respMsg;
		}

		public String getTransNo() {
			return transNo;
		}

		public void setTransNo(String transNo) {
			this.transNo = transNo;
		}

		public String getSuccAmt() {
			return succAmt;
		}

		public void setSuccAmt(String succAmt) {
			this.succAmt = succAmt;
		}

		public String getReqReserved() {
			return reqReserved;
		}

		public void setReqReserved(String reqReserved) {
			this.reqReserved = reqReserved;
		}
    }
	
	public static void main(String[] args) {
		String test = "{\"actual_info\":{\"info\":[\"1493364217954#F#BF00325#订单格式不正确,分隔符缺失###\",\"1493364217955#F#BF00325#订单格式不正确,分隔符缺失###\"]},\"member_id\":\"100000178\",\"resp_code\":\"0000\",\"resp_msg\":\"查询成功\",\"terminal_id\":\"100000916\"} ";
		JSONObject json = JSONObject.parseObject(test);
		QueryPayinBatchOrderBaoFuContent content = JSONObject.toJavaObject(json, QueryPayinBatchOrderBaoFuContent.class);
		Map m = (Map)json.get("actual_info");
		List<String> infoLs = (List)m.get("info");
		List<QueryPayinBatchContentItem> items = Lists.newArrayList();
		for(String info : infoLs){
			List<String> itemData = Splitter.on(QueryPayinBatchContentItem.ENCRYPTSEPERATOR).splitToList(info);
			QueryPayinBatchContentItem item = new QueryPayinBatchContentItem();
			item.setTransId(itemData.get(0));
			item.setOrderStat(itemData.get(1));
			item.setRespCode(itemData.get(2));
			item.setRespMsg(itemData.get(3));
			item.setTransNo(itemData.get(4));
			item.setSuccAmt(itemData.get(5));
			item.setReqReserved(itemData.get(6));
			items.add(item);
		}
		content.setItems(items);
		System.out.println(content);

	}
	
}
